// 1. 处理中文参数
const chinese = '你好世界'
const encoded = encodeURIComponent(chinese)
console.log('1 ', encoded) // 输出: "%E4%BD%A0%E5%A5%BD%E4%B8%96%E7%95%8C"
console.log(decodeURIComponent(encoded)) // 输出: "你好世界"

// 2. 处理 URL 特殊字符
const url = 'https://example.com?name=John&age=25'
const encodedUrl = encodeURIComponent(url)
console.log('2 ', encodedUrl)
console.log(decodeURIComponent(encodedUrl))

// 3. 实际应用场景：构建 URL 查询参数
const params = {
  name: '张三',
  company: 'ABC Company & Partners',
  role: '开发者'
}

const queryString = Object.entries(params)
  .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
  .join('&')

console.log('3 ', queryString)
